'use strict';
const cloudStorage = uniCloud.cloudStorage();

exports.main = async (event, context) => {
    console.log('云函数 uploadFile 被调用', event); // 打印日志
    const { fileContent, fileName } = event;

    try {
        const result = await cloudStorage.uploadFile({
            fileContent: fileContent,
            cloudPath: `uploads/${fileName}`
        });

        return {
            code: 0,
            message: 'success',
            data: result.fileID
        };
    } catch (error) {
        console.error('文件上传失败', error); // 打印错误日志
        return {
            code: -1,
            message: '文件上传失败',
            data: null
        };
    }
};